{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 第五次练习"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "+ 请务必交到exer5文件夹下，**谢绝交到master下**\n",
    "+ 请不要改动任何文件，拜托\n",
    "+ 请在11月7日前提交。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "请写一下姓名和学号：\n",
    "+ 姓名  刘婷婷\n",
    "+ 学号   0154590"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目一、贫困户模型\n",
    "+ 创建一个类，包含贫困户的义务教育保障、住房安全、饮水安全、肉蛋奶豆的四个属性\n",
    "+ 包含一个是否贫困的预测，如果四个属性有两个以上没有保障（>2)则输出为贫困户\n",
    "+ 对贫困户，采取相应措施（输入参数）对其进行帮扶，使其脱贫\n",
    "+ 至少生成三个实例\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "贫困户\n",
      "None None 通水 送食物\n",
      "非贫困户\n",
      "建小学 None None None\n",
      "非贫困户\n"
     ]
    }
   ],
   "source": [
    "class Poverty(object):\n",
    "    def __init__(self, edu=True, house=True, water=False, food=False):\n",
    "        self.edu = edu\n",
    "        self.house = house\n",
    "        self.water = water\n",
    "        self.food = food\n",
    "    def isPoverty(self):\n",
    "        list = [self.edu, self.house, self.water, self.food]\n",
    "        if sum(list) <3:\n",
    "            print('贫困户')\n",
    "        else:\n",
    "            print('非贫困户')\n",
    "    def help(self, edu=None, house=None, water=None, food=None):\n",
    "        print(edu,house,water,food)\n",
    "a = Poverty(edu=True, house=True, water=False, food=False)\n",
    "a.isPoverty()\n",
    "a.help( water='通水', food='送食物')\n",
    "\n",
    "b = Poverty(edu=False, house=True, water=True, food=True)\n",
    "b.isPoverty()\n",
    "b.help( edu='建小学')\n",
    "\n",
    "c = Poverty(edu=True, house=True, water=True, food=True)\n",
    "c.isPoverty()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目二: 学生信息\n",
    "+ 创建一个类，包含姓名、分数、睡眠时间三个属性\n",
    "+ 包含一个胖瘦的预测，如果分数>90，且睡眠时间少于6小时，输出“BMI可能偏大”，否则输出“体重正常”\n",
    "+ 为使得标准（90分、6小时）可以调整，标准应设为输入的参数\n",
    "+ 至少生成三个实例"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "体重正常\n",
      "\n",
      "BMI可能偏大\n",
      "\n",
      "BMI可能偏大\n",
      "\n"
     ]
    }
   ],
   "source": [
    "class Student(object):\n",
    "    def __init__(self, name, score, sleep):\n",
    "        self.name = name\n",
    "        self.score = score\n",
    "        self.sleep = sleep\n",
    "        \n",
    "    def weight_predict(self, scoreStandard=90, sleepStandard=6):\n",
    "        if self.score > scoreStandard and self.sleep < sleepStandard:\n",
    "            print(\"BMI可能偏大\")\n",
    "        else:\n",
    "            print(\"体重正常\")\n",
    "            \n",
    "student = Student(\"小花\", 90, 6)\n",
    "student.weight_predict()\n",
    "print()\n",
    "\n",
    "student = Student(\"毛毛\", 95, 5)\n",
    "student.weight_predict(80, 8)\n",
    "print()\n",
    "\n",
    "student = Student(\"奶牛\", 85, 7)\n",
    "student.weight_predict(80, 8)\n",
    "print()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目三：“跑步社”成员类\n",
    "+ 创建一个“跑步社”成员类，以学生信息类为父类\n",
    "+ 添加一个属性为跑步\n",
    "+ 如果跑步时间大于30分钟，如果之前预测为“BMI可能偏大”，则输出为“趋向正常”\n",
    "+ 至少生成三个实例"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "体重正常\n",
      "\n",
      "趋向正常\n",
      "\n",
      "体重正常\n",
      "\n"
     ]
    }
   ],
   "source": [
    "class Runner(Student):\n",
    "    def __init__(self, run, name, score, sleep):\n",
    "        self.run = run\n",
    "        super().__init__(name, score, sleep)\n",
    "    def weight_predict(self, scoreStandard=90, sleepStandard=6, runStandard=30):\n",
    "        condition = self.score > scoreStandard and self.sleep < sleepStandard\n",
    "        if condition and self.run > runStandard:\n",
    "            print(\"趋向正常\")\n",
    "        elif condition:\n",
    "            print(\"BMI可能偏大\")\n",
    "        else:\n",
    "            print(\"体重正常\")\n",
    "            \n",
    "runner = Runner(31, \"小花\", 90, 6)\n",
    "runner.weight_predict()\n",
    "print()\n",
    "\n",
    "runner = Runner(26, \"毛毛\", 96, 5)\n",
    "runner.weight_predict(scoreStandard=85, runStandard=25)\n",
    "print()\n",
    "\n",
    "runner = Runner(31, \"奶牛\", 85, 7)\n",
    "runner.weight_predict(scoreStandard=85, sleepStandard=7, runStandard=25)\n",
    "print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
